"""
爬取百度贴吧帖子
"""

import requests
from datetime import datetime


def spider_tie_ba(url):
    print(f"开始爬取链接{url}")
    response = requests.get(url)
    response.encoding = "utf-8"
    file_name = "./files/" + datetime.now().strftime("%Y%m%d%H%M%S") + ".txt"
    file_obj = open(file_name, "w")
    file_obj.write(response.text)
    file_obj.flush()
    file_obj.close()
    print(f"爬虫结束，已经生成文件，文件路径为{file_name}")


if __name__ == "__main__":
    url = "http://tieba.baidu.com/p/6301339610"
    spider_tie_ba(url)


